/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import Funcoes.Funcao;

import classes.Equipamento;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.swing.JOptionPane;

/**
 *
 * @author BRUNO E ALEX
 */
public class cadastroEquipamento extends javax.swing.JInternalFrame {

    EntityManager gerenciador;
    Query consulta;

    Equipamento equipamento = new Equipamento();

    /**
     * Creates new form cadastroEquipamento
     */
    public cadastroEquipamento() {

        initComponents();

        this.reiniciaFormulario();

        txt_nome.setEnabled(false);
        txt_codigo_equip.setEnabled(false);
        txt_preco.setEnabled(false);

        txt_info.setEnabled(false);
        btn_limpar_equip.setEnabled(false);
        btn_salvar_equip.setEnabled(false);
        btn_cancelar_equip.setEnabled(false); // comando desativa botoes ao iniciar a tela
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painel_cadEquip = new javax.swing.JPanel();
        lbl_preco_equip = new javax.swing.JLabel();
        lbl_nome_equip = new javax.swing.JLabel();
        lbl_cod_equip1 = new javax.swing.JLabel();
        txt_nome = new javax.swing.JTextField();
        txt_codigo_equip = new javax.swing.JTextField();
        txt_preco = new javax.swing.JTextField();
        lbl_codigo_equip = new javax.swing.JLabel();
        lbl_quantidade = new javax.swing.JLabel();
        estoque = new javax.swing.JTextField();
        lbl_numero = new javax.swing.JLabel();
        painel_cadEquip2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txt_info = new javax.swing.JTextArea();
        equi_lbl5 = new javax.swing.JLabel();
        btn_novo_equip = new javax.swing.JButton();
        btn_limpar_equip = new javax.swing.JButton();
        btn_salvar_equip = new javax.swing.JButton();
        btn_cancelar_equip = new javax.swing.JButton();
        btn_alterar_equip = new javax.swing.JButton();
        painel_cad2 = new javax.swing.JPanel();
        lbl_cod_equip2 = new javax.swing.JLabel();
        btn_buscar_equip = new javax.swing.JButton();
        btn_anterior_equip = new javax.swing.JButton();
        txt_buscar_equip = new javax.swing.JTextField();
        btn_proximo_equip = new javax.swing.JButton();

        setClosable(true);
        setTitle("Cadastro de Equipamento");
        setPreferredSize(new java.awt.Dimension(650, 470));

        painel_cadEquip.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl_preco_equip.setText("Preço:");

        lbl_nome_equip.setText("Nome do Equipamento:");

        lbl_cod_equip1.setText("Código do Equipamento:");

        txt_nome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_nomeActionPerformed(evt);
            }
        });

        txt_codigo_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_codigo_equipActionPerformed(evt);
            }
        });

        txt_preco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_precoActionPerformed(evt);
            }
        });

        lbl_codigo_equip.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        lbl_codigo_equip.setForeground(new java.awt.Color(204, 0, 0));
        lbl_codigo_equip.setToolTipText("codigo do equipamento");

        lbl_quantidade.setText("Quantidade :");

        lbl_numero.setText("Numero do Cadastro:");

        javax.swing.GroupLayout painel_cadEquipLayout = new javax.swing.GroupLayout(painel_cadEquip);
        painel_cadEquip.setLayout(painel_cadEquipLayout);
        painel_cadEquipLayout.setHorizontalGroup(
            painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cadEquipLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbl_cod_equip1)
                    .addComponent(lbl_nome_equip)
                    .addComponent(lbl_numero, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painel_cadEquipLayout.createSequentialGroup()
                        .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txt_codigo_equip, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txt_nome, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE))
                        .addGap(53, 53, 53)
                        .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_preco_equip)
                            .addComponent(lbl_quantidade))
                        .addGap(30, 30, 30)
                        .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(estoque, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txt_preco, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(61, 61, 61))
                    .addGroup(painel_cadEquipLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(lbl_codigo_equip, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        painel_cadEquipLayout.setVerticalGroup(
            painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cadEquipLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_nome_equip)
                    .addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_preco_equip)
                    .addComponent(txt_preco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_codigo_equip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_cod_equip1)
                    .addComponent(lbl_quantidade)
                    .addComponent(estoque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painel_cadEquipLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbl_codigo_equip, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbl_numero))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        painel_cadEquip2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        txt_info.setColumns(20);
        txt_info.setRows(5);
        jScrollPane1.setViewportView(txt_info);

        javax.swing.GroupLayout painel_cadEquip2Layout = new javax.swing.GroupLayout(painel_cadEquip2);
        painel_cadEquip2.setLayout(painel_cadEquip2Layout);
        painel_cadEquip2Layout.setHorizontalGroup(
            painel_cadEquip2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cadEquip2Layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painel_cadEquip2Layout.setVerticalGroup(
            painel_cadEquip2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cadEquip2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        equi_lbl5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        equi_lbl5.setText("Informações do Equipamento");

        btn_novo_equip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_novo.png"))); // NOI18N
        btn_novo_equip.setText(" Novo");
        btn_novo_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_novo_equipActionPerformed(evt);
            }
        });

        btn_limpar_equip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/stop.png"))); // NOI18N
        btn_limpar_equip.setText("Limpar");
        btn_limpar_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_limpar_equipActionPerformed(evt);
            }
        });

        btn_salvar_equip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/accept.png"))); // NOI18N
        btn_salvar_equip.setText("Salvar");
        btn_salvar_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salvar_equipActionPerformed(evt);
            }
        });

        btn_cancelar_equip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/remove.png"))); // NOI18N
        btn_cancelar_equip.setText("Cancelar");
        btn_cancelar_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelar_equipActionPerformed(evt);
            }
        });

        btn_alterar_equip.setText("Alterar");
        btn_alterar_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_alterar_equipActionPerformed(evt);
            }
        });

        painel_cad2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl_cod_equip2.setText("Código do Equipamento:");

        btn_buscar_equip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_procurar.png"))); // NOI18N
        btn_buscar_equip.setText("Buscar");
        btn_buscar_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscar_equipActionPerformed(evt);
            }
        });

        btn_anterior_equip.setText("Anterior");
        btn_anterior_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_anterior_equipActionPerformed(evt);
            }
        });

        txt_buscar_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_buscar_equipActionPerformed(evt);
            }
        });

        btn_proximo_equip.setText("Próximo");
        btn_proximo_equip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_proximo_equipActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painel_cad2Layout = new javax.swing.GroupLayout(painel_cad2);
        painel_cad2.setLayout(painel_cad2Layout);
        painel_cad2Layout.setHorizontalGroup(
            painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_cad2Layout.createSequentialGroup()
                .addContainerGap(34, Short.MAX_VALUE)
                .addComponent(btn_anterior_equip, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btn_proximo_equip, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbl_cod_equip2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txt_buscar_equip, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_buscar_equip)
                .addContainerGap())
        );
        painel_cad2Layout.setVerticalGroup(
            painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_cad2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painel_cad2Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(txt_buscar_equip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(painel_cad2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lbl_cod_equip2)
                        .addComponent(btn_buscar_equip)
                        .addComponent(btn_anterior_equip)
                        .addComponent(btn_proximo_equip)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btn_novo_equip)
                                .addGap(34, 34, 34)
                                .addComponent(btn_cancelar_equip)
                                .addGap(45, 45, 45)
                                .addComponent(btn_salvar_equip)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btn_limpar_equip)
                                .addGap(30, 30, 30)
                                .addComponent(btn_alterar_equip, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(11, 11, 11))
                            .addComponent(painel_cadEquip2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(painel_cadEquip, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(painel_cad2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(195, 195, 195)
                        .addComponent(equi_lbl5)))
                .addContainerGap(11, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_novo_equip)
                    .addComponent(btn_cancelar_equip)
                    .addComponent(btn_salvar_equip)
                    .addComponent(btn_limpar_equip)
                    .addComponent(btn_alterar_equip))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(painel_cad2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(painel_cadEquip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(equi_lbl5)
                .addGap(18, 18, 18)
                .addComponent(painel_cadEquip2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_cancelar_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelar_equipActionPerformed

        this.reiniciaFormulario();

    }//GEN-LAST:event_btn_cancelar_equipActionPerformed

    private void btn_salvar_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salvar_equipActionPerformed
        gerenciador = Funcoes.Funcao.conectar();

        equipamento.setEqui_nome(this.txt_nome.getText());
        equipamento.setEqui_quant(Integer.parseInt(this.estoque.getText()));
        equipamento.setEqui_cod(this.txt_codigo_equip.getText());
        equipamento.setEqui_preco(this.txt_preco.getText());

        equipamento.setEqui_inf(this.txt_info.getText());

        Funcoes.Funcao.persistir(gerenciador, equipamento);
        Funcoes.Funcao.fechar(gerenciador);//fecha conecxão 

        this.txt_nome.setText("");
        this.txt_codigo_equip.setText("");
        this.txt_preco.setText("");

        this.txt_info.setText("");

        this.reiniciaFormulario();

        JOptionPane.showMessageDialog(null, "Cadastro efetuado com sucesso!"); // se salvou retorna ok 

    }//GEN-LAST:event_btn_salvar_equipActionPerformed

    private void btn_novo_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_novo_equipActionPerformed
        txt_nome.setEnabled(true);
        txt_codigo_equip.setEnabled(true);
        txt_preco.setEnabled(true);

        txt_info.setEnabled(true);
        btn_limpar_equip.setEnabled(true);
        btn_salvar_equip.setEnabled(true);
        btn_cancelar_equip.setEnabled(true);
        // Ativa Todos os botoes ao clicar
    }//GEN-LAST:event_btn_novo_equipActionPerformed

    private void btn_limpar_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_limpar_equipActionPerformed
        txt_nome.setText(null);
        txt_codigo_equip.setText(null);
        txt_preco.setText(null);

        txt_info.setText(null);        // Apaga o que já foi digitado
    }//GEN-LAST:event_btn_limpar_equipActionPerformed

    private void btn_alterar_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_alterar_equipActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null, "Deseja alterar este Equipamento ?", "Finalizando o cadastro ", JOptionPane.YES_NO_OPTION);

        if (resposta == 0) {

            gerenciador = Funcao.conectar();

//            equipamento.setId(Integer.parseInt(this.codigo.getText()));
            equipamento.setEqui_nome(this.txt_nome.getText());
            equipamento.setEqui_cod(this.txt_codigo_equip.getText());
            equipamento.setEqui_preco(this.txt_preco.getText());
            equipamento.setEqui_quant(Integer.parseInt(this.estoque.getText()));

            equipamento.setEqui_inf(this.txt_info.getText());

            consulta = gerenciador.createQuery("select c from Equipamento c where c.equi_cod = :equi_cod");
            consulta.setParameter("equi_cod", equipamento.getEqui_cod());
            gerenciador.getTransaction().begin();
            gerenciador.merge(equipamento);
            gerenciador.getTransaction().commit();

            JOptionPane.showMessageDialog(null, "Alterado com sucesso !");

        } else {

            this.reiniciaFormulario();

        }
    }//GEN-LAST:event_btn_alterar_equipActionPerformed

    private void btn_buscar_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscar_equipActionPerformed

        gerenciador = Funcao.conectar();

        consulta = gerenciador.createQuery("select c from Equipamento c where c.equi_cod = :equi_cod"); //HQl
        consulta.setParameter("equi_cod", txt_buscar_equip.getText());

        equipamento = (Equipamento) consulta.getSingleResult();

        this.lbl_codigo_equip.setText("" + equipamento.getIdEquip());
        this.txt_nome.setText(equipamento.getEqui_nome());
        this.estoque.setText(""+ equipamento.getEqui_quant());
        this.txt_codigo_equip.setText(equipamento.getEqui_cod());
        this.txt_preco.setText(equipamento.getEqui_preco());
        this.txt_info.setText(equipamento.getEqui_inf());

        this.txt_nome.setEnabled(true);
        this.txt_codigo_equip.setEnabled(true);
        this.txt_preco.setEnabled(true);
        this.txt_info.setEnabled(true);
        this.estoque.setEnabled(true);

        this.txt_buscar_equip.setText("");
        this.btn_anterior_equip.setEnabled(true);
        this.btn_proximo_equip.setEnabled(true);
        this.btn_cancelar_equip.setEnabled(true);
        this.btn_novo_equip.setEnabled(false);
        this.btn_alterar_equip.setEnabled(true);

        Funcao.fechar(gerenciador);
    }//GEN-LAST:event_btn_buscar_equipActionPerformed

    private void btn_anterior_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_anterior_equipActionPerformed
        gerenciador = Funcao.conectar();

        try {//TRATAMENTO DE ERROS
            //Seleciona apenas o primeiro registro com o id menor que o passado
            consulta = gerenciador.createQuery("select c from Equipamento c where c.idEquip < :idEquip order by c.idEquip desc");//HQL
            consulta.setParameter("idEquip", Integer.parseInt(this.lbl_codigo_equip.getText())); //Compara o id do banco com o id do parâmetro
            consulta.setMaxResults(1);//Captura o primeiro registro
            equipamento = (Equipamento) consulta.getSingleResult();

            this.lbl_codigo_equip.setText("" + equipamento.getIdEquip());
            this.txt_nome.setText(equipamento.getEqui_nome());
            this.txt_codigo_equip.setText(equipamento.getEqui_cod());
            this.txt_preco.setText(equipamento.getEqui_preco());
            this.estoque.setText(""+equipamento.getEqui_quant());
            this.txt_info.setText(equipamento.getEqui_inf());

        } catch (NoResultException ex) {
            JOptionPane.showMessageDialog(null, "Esse é o primeiro registro",
                    "Informativo", JOptionPane.INFORMATION_MESSAGE);
        }//TRY CATCH

        Funcao.fechar(gerenciador);
    }//GEN-LAST:event_btn_anterior_equipActionPerformed

    private void txt_buscar_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_buscar_equipActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_buscar_equipActionPerformed

    private void btn_proximo_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_proximo_equipActionPerformed

        gerenciador = Funcao.conectar();

        try {//TRATAMENTO DE ERROS
            //Seleciona apenas o primeiro registro com o id menor que o passado
            consulta = gerenciador.createQuery("select c from Equipamento c where c.idEquip > :idEquip");//HQL
            consulta.setParameter("idEquip", equipamento.getIdEquip()); //Compara o id do banco com o id do parâmetro
            consulta.setMaxResults(1);//Captura o primeiro registro
            equipamento = (Equipamento) consulta.getSingleResult();

            this.lbl_codigo_equip.setText("" + equipamento.getIdEquip());
            this.txt_nome.setText(equipamento.getEqui_nome());
            this.txt_codigo_equip.setText(equipamento.getEqui_cod());
            this.txt_preco.setText(equipamento.getEqui_preco());
            this.estoque.setText(""+ equipamento.getEqui_quant());
            this.txt_info.setText(equipamento.getEqui_inf());

        } catch (NoResultException ex) {
            JOptionPane.showMessageDialog(null, "Esse é o último registro",
                    "Informativo", JOptionPane.INFORMATION_MESSAGE);
        }//TRY CATCH

        Funcao.fechar(gerenciador);
    }//GEN-LAST:event_btn_proximo_equipActionPerformed

    private void txt_precoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_precoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_precoActionPerformed

    private void txt_codigo_equipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_codigo_equipActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_codigo_equipActionPerformed

    private void txt_nomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_nomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_nomeActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_alterar_equip;
    private javax.swing.JButton btn_anterior_equip;
    private javax.swing.JButton btn_buscar_equip;
    private javax.swing.JButton btn_cancelar_equip;
    private javax.swing.JButton btn_limpar_equip;
    private javax.swing.JButton btn_novo_equip;
    private javax.swing.JButton btn_proximo_equip;
    private javax.swing.JButton btn_salvar_equip;
    private javax.swing.JLabel equi_lbl5;
    private javax.swing.JTextField estoque;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbl_cod_equip1;
    private javax.swing.JLabel lbl_cod_equip2;
    private javax.swing.JLabel lbl_codigo_equip;
    private javax.swing.JLabel lbl_nome_equip;
    private javax.swing.JLabel lbl_numero;
    private javax.swing.JLabel lbl_preco_equip;
    private javax.swing.JLabel lbl_quantidade;
    private javax.swing.JPanel painel_cad2;
    private javax.swing.JPanel painel_cadEquip;
    private javax.swing.JPanel painel_cadEquip2;
    private javax.swing.JTextField txt_buscar_equip;
    private javax.swing.JTextField txt_codigo_equip;
    private javax.swing.JTextArea txt_info;
    private javax.swing.JTextField txt_nome;
    private javax.swing.JTextField txt_preco;
    // End of variables declaration//GEN-END:variables

    public void reiniciaFormulario() {

        this.btn_novo_equip.setEnabled(true);
        this.btn_alterar_equip.setEnabled(false);
        this.btn_anterior_equip.setEnabled(false);
        this.btn_cancelar_equip.setEnabled(false);
        this.btn_limpar_equip.setEnabled(false);
        this.btn_proximo_equip.setEnabled(false);
        this.btn_salvar_equip.setEnabled(false);
        this.btn_buscar_equip.setEnabled(true);

        this.txt_nome.setEnabled(false);
        this.txt_codigo_equip.setEnabled(false);
        this.txt_preco.setEnabled(false);

        this.txt_info.setEnabled(false);
        this.txt_buscar_equip.setEnabled(true);

        this.txt_nome.setText("");
        this.txt_codigo_equip.setText("");
        this.txt_preco.setText("");

        this.txt_info.setText("");

    }
}
